package com.cskaoyan.shopping.controller.zyl_Conteroller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.shopping.converter.ContentConverter;
import com.cskaoyan.shopping.dal.entitys.Panel;
import com.cskaoyan.shopping.dal.entitys.PanelContent;
import com.cskaoyan.shopping.dal.entitys.PanelContentItem;
import com.cskaoyan.shopping.dto.PanelContentDto;
import com.cskaoyan.shopping.dto.PanelContentItemDto;
import com.cskaoyan.shopping.dto.PanelDto;
import com.cskaoyan.shopping.dto.TestProductDetailDto;
import com.cskaoyan.shopping.service.zyl_homepage_and_anvigation.PanelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

@RestController
public class zyl_homepage_and_navigation {

    @Autowired
    PanelService panelService;

    @Autowired
    ContentConverter contentConverter;

    /**
     * 主页显示接口
     */
    @GetMapping("/shopping/homepage")
    public ResponseData getProductDetail() {
        List<Panel> panels = panelService.selevt_Panel();
        List<PanelDto> panelDtos = contentConverter.panels2Dto(panels);
        for (PanelDto dto : panelDtos) {
            List<PanelContentItem> panelContentItems = panelService.selectPanelContentAndProductWithPanelId(dto.getId());
            List<PanelContentItemDto> panelContentItemDtos = contentConverter.panelContentItem2Dto(panelContentItems);
            dto.setPanelContentItems(panelContentItemDtos);
        }
        return new ResponseUtil().setData(panelDtos);
    }

    /**
     * 导航栏显示
     */
    @GetMapping("/shopping/navigation")
    public ResponseData navigation() {

        List<PanelContent> panelContents = panelService.selectPanelContents(0);
        System.out.println("panelContents = " + panelContents);

        return new ResponseUtil().setData(panelContents);
    }

}
